#ifndef SMARTPOINTER_H
#define SMARTPOINTER_H

template
< typename T >
class smartpointer
{
    T* mp;
public:
    smartpointer(T* p = nullptr)
    {
        mp = p;
    }

    smartpointer(const smartpointer<T>& obj)
    {
        mp = obj.mp;
        const_cast<smartpointer<T>&>(obj).mp = nullptr;
    }

    smartpointer<T>& operator = (const smartpointer<T>& obj)
    {
        if( this != &obj )
        {
            delete mp;
            mp = obj.mp;
            const_cast<smartpointer<T>&>(obj).mp = nullptr;
        }

        return *this;
    }

    T* operator -> ()
    {
        return mp;
    }

    T& operator * ()
    {
        return *mp;
    }

    bool isNull()
    {
        return (mp == nullptr);
    }

    T* get()
    {
        return mp;
    }

    ~SmartPointer()
    {
        delete mp;
    }
};
#endif // SMARTPOINTER_H
